/**
 * 
 */
package cn.edu.nju.software.tags;

import java.io.IOException;

import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;

/**
 * @author yuqi
 *
 */
public class checkSessionHandler extends SimpleTagSupport {

	public void doTag() throws JspException,IOException{
		try {
			boolean valid = false;
			PageContext pageContext = (PageContext)getJspContext();
			HttpSession session = pageContext.getSession();
			if ((session != null) && (session.getAttribute("login") != null))
			    valid = true;
			if (valid)
				return;
			else {
			    try {
				pageContext.forward("login.jsp");
			    } catch (Exception e) {
				throw new JspException(e.toString());
			    }
			    return;
			}

		}catch (Exception e) {
			e.printStackTrace();
		}
	}

}
